package com.mathpractise.question.generator;

import com.mathpractise.model.Question;
import com.mathpractise.model.TrainingConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * 抽象题目生成器
 * 
 * 提取题目生成器的公共逻辑，确保所有子类遵循统一的处理流程
 */
public abstract class AbstractQuestionGenerator implements QuestionGenerator {
    
    @Override
    public List<Question> generateQuestions(TrainingConfig trainingConfig) {
        List<Question> questions = new ArrayList<>();
        int count = trainingConfig.getQuestionCount();
        
        for (int i = 0; i < count; i++) {
            questions.add(generateQuestion(trainingConfig));
        }
        
        return questions;
    }
    
    @Override
    public final Question generateQuestion(TrainingConfig trainingConfig) {
        // 调用子类实现的具体题目生成逻辑
        Question question = doGenerateQuestion(trainingConfig);
        
        // 确保题目类型与生成器支持的类型一致
        question.setQuestionType(getSupportedType());
        
        return question;
    }
    
    /**
     * 子类实现具体的题目生成逻辑
     * 
     * @param trainingConfig 训练配置
     * @return 生成的题目
     */
    protected abstract Question doGenerateQuestion(TrainingConfig trainingConfig);
}